package net.confinanz.client.frontend.plugins;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;

import net.confinanz.client.frontend.ConfinanzGui;

public class OnlinePlugin extends AbstractPlugin {
	
	private final String caption = "Online-Verwaltung";
	private final String BUTTON_ICON_RESSCOURCE = "/net/confinanz/client/frontend/icons/64x64/onlineAccount.png";
	
	private JPanel content;

	public OnlinePlugin(ConfinanzGui frame) {
		super(frame);
		this.title = caption;
		this.buttonIcon = BUTTON_ICON_RESSCOURCE;
	}

	@Override
	public String getTitle() {
		return this.title;
	}

	@Override
	public JButton getButton() {
		if (buttonToolbar == null) {
			if (buttonIcon == null) {
				buttonToolbar = new JButton(title);
			} else {
				buttonToolbar = new JButton();
				buttonToolbar.setIcon(new ImageIcon(getClass().getResource(BUTTON_ICON_RESSCOURCE)));
			}

			buttonToolbar.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					getGui().setContentPane(getContentPane());
					getGui().setVisible(true);
				}
			});
		}
		return buttonToolbar;
	}

	@Override
	public JPanel getContent() {
		if (content == null) {
			content = new JPanel();
			content.setLayout(new BorderLayout());
			content.add(new DefaultScrollPane(new OnlineContent()), BorderLayout.CENTER);
		}
		return content;
	}
}